<?php
use CTCF\Controller;
use CTCF\Model;
use CTCF\CTCFCache;

class Home__IndexController extends Controller{
	public function index(){
		$res = array('matchNums'=>0,'matchPercent'=>0,'matchPrice'=>0,'mathPricePercent');
		$Model = new Model('recycle_book');
		$datas = $Model->select(['isbn','id','saleprice'],['status'=>1]);
		$res['checkNums'] = count($datas);
		$res['price'] = $Model->sum('saleprice');
		foreach ($datas as $k=>$v){
			$newBook = new Model('teach_book');
			$st = $newBook->has(['isbn'=>$v['isbn']]);
			if($st){
				$res['matchNums']++;
				$res['matchPrice'] += $v['saleprice'];
			}
		}
		$res['matchPercent'] = round($res['matchNums']/$res['checkNums']*100,2);
		$res['matchPricePercent'] = round($res['matchPrice']/$res['price']*100,2);
		$res['date'] = date('Y-m-d');
		$this->res = $res;
		$this->display('matchresult.html');
	}
	
	public function show(){
		CTCFCache::s('date', date('YmdH:i:s'));
		echo CTCFCache::g('date');
		$this->display('hello.html');
	}
}